package com.etlmaster.executor.steps.control;

import java.util.List;
import java.util.Map;

import com.etlmaster.executor.EtlMasterException;
import com.etlmaster.executor.Job;
import com.etlmaster.executor.StepMeta;
import com.etlmaster.executor.steps.control.ConditionalStepInterface;

/**
 * 
 * @author MeiKefu
 * @date 2014-8-4
 */
public class ConditionalStepMeta extends ConditionalStepInterface{
	
	private List<Map<String,String>> statements;
	public ConditionalStepMeta(String id, String name,String step_code, String sessionid, String paramStr) {
		super(id, name,step_code, sessionid, paramStr);
	}

	public List<Map<String,String>> getStatements() {
		return statements;
	}

	@Override
	public StepMeta process(StepMeta curStepMeta, Job job) {
		curStepMeta.log("INFO","开始执行步骤：{}",curStepMeta.getName());
		StepMeta stepMeta=getNextStepMeta(curStepMeta,job);

		curStepMeta.log("INFO","该步骤成功下一步：{}", stepMeta.getId());
		return stepMeta;
	}
	public StepMeta getNextStepMeta(StepMeta curStepMeta, Job job){
		//curStepMeta.setVariables(Collections.unmodifiableMap(job.getVariables()));
		ConditionalStep conditionalStep = (ConditionalStep)curStepMeta.getStep();
		StepMeta stepMeta=conditionalStep.getSuccessStep(job);
		if(stepMeta instanceof ConditionalStepInterface){
			stepMeta=getNextStepMeta(stepMeta,job);
		}
		return stepMeta;
	}

	@Override
	public StepMeta processForStack(StepMeta curStepMeta, Job job)
			throws EtlMasterException {
		StepMeta stepMeta=getNextStepMeta(curStepMeta,job);

		return stepMeta;
	}
}
